import Vue from "vue";
import VueI18n from "vue-i18n";
import enUS from "./lang/en-US";
import zhCN from "./lang/zh-CN";
import storage from "../utils/storage";
import moment from "moment";

Vue.use(VueI18n);

const i18n = new VueI18n({
  locale: "zh-CN",
  messages: {
    "zh-CN": { message: zhCN },
    "en-US": { message: enUS }
  }
});

export function setLang(lang) {
  storage.setItem("lang", lang);

  i18n.locale = lang;
  moment.locale(i18n.getLocaleMessage(lang).message.momentName);

  document.querySelector("html").setAttribute("lang", lang); // request.headers["Accept-Language"] = lang;
  return lang;
}

export default i18n;
